package com.hgyc.mom.tool.controller;

import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.tool.entity.AutoCodePart;
import com.hgyc.mom.tool.service.AutoCodePartService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 编码生成规则组成Controller
 *
 * @author fwj
 * @since 2025-05-06
 */
@Tag(name = "编码生成规则组成控制器", description = "编码生成规则组成控制器")
@RestController
@RequestMapping("/tool/part")
public class AutoCodePartController {
    @Autowired
    private AutoCodePartService autoCodePartService;

    @Operation(summary = "查询编码生成规则组成列表", description = "查询编码生成规则组成列表")
    @GetMapping("/list/{ruleId}")
    public Result<List<AutoCodePart>> pageList(@Parameter(description = "查询参数") @PathVariable("ruleId") Long ruleId) {
        List<AutoCodePart> list = autoCodePartService.getByRuleId(ruleId);
        return Result.success(list);
    }

    @Operation(summary = "新增编码生成规则组成", description = "新增编码生成规则组成")
    @PostMapping
    public Result save(@Parameter(description = "编码生成规则组成") @RequestBody List<AutoCodePart> partList) {
        autoCodePartService.saveList(partList);
        return Result.success();
    }

}